package org.totoro.structure.queue.impl;


import org.totoro.structure.list.impl.ArrayList;
import org.totoro.structure.queue.Queue;
import org.totoro.structure.stack.impl.ArrayStack;

/**
 * 队列
 * 先进先出 特性
 *
 * @author daocr
 * @date 2020/3/22
 */
public class ArrayQueue<E> implements Queue<E> {

    private ArrayList<E> list;

    public ArrayQueue() {
        list = new ArrayList<>();
    }

    @Override
    public void enqueue(E e) {
        list.add(0, e);
    }

    @Override
    public E dequeue() {
        E e = list.getLast();
        list.remove(e);
        return e;
    }

    @Override
    public E getFirst() {
        return list.get(0);
    }

    @Override
    public int getSize() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    public static void main(String[] args) {

        ArrayQueue<String> stringArrayQueue = new ArrayQueue<>();

        for (int i = 0; i < 100; i++) {
            stringArrayQueue.enqueue(String.valueOf(i));
        }

        for (int i = 0; i < 50; i++) {
            stringArrayQueue.dequeue();
        }


        String dequeue = null;

        while ((dequeue = stringArrayQueue.dequeue()) != null) {
            System.out.println(dequeue);
        }


    }
}
